package com.wwp.tbshop.view.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.wwp.tbshop.R;
import com.wwp.tbshop.model.bean.HomeFragmentPicsBean;
import com.wwp.tbshop.util.UiUtil;
import com.wwp.tbshop.view.fragment.HomeFragment;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by ${wenping} on 6/18/2017.
 */

public class HomeFragmentPicRvAdapter extends RecyclerView.Adapter {

    private HomeFragment mHomeFragment;

    private List<HomeFragmentPicsBean> picLists;

    public HomeFragmentPicRvAdapter(HomeFragment homeFragment, List<HomeFragmentPicsBean> picLists) {
        mHomeFragment = homeFragment;
        this.picLists = picLists;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(UiUtil.getContext(), R.layout.item_home_pics, null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.setData(picLists.get(position));
    }

    @Override
    public int getItemCount() {
        return picLists.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.item_home_pic)
        ImageView mItemHomePic;
        @Bind(R.id.home_pic_name)
        TextView mHomePicName;
        @Bind(R.id.home_pic_price)
        TextView mHomePicPrice;
        @Bind(R.id.home_pic_marketprice)
        TextView mHomePicMarketprice;
        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void setData(HomeFragmentPicsBean bean) {
            Picasso.with(UiUtil.getContext())
                    .load(bean.getResId())
                    .into(mItemHomePic);
            mHomePicName.setText(bean.getPicName()+"");
            mHomePicName.setTextColor(Color.RED);
            mHomePicPrice.setText("惊喜价:¥ "+bean.getPicPrice()+"");
            mHomePicPrice.setTextColor(Color.RED);
            mHomePicMarketprice.setText("市价:¥ "+bean.getPicMarketPrice()+"");
            mHomePicMarketprice.setTextColor(Color.BLACK);
        }
    }
}
